﻿<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">

      <div class="table-page-search-wrapper" v-if="hasPerm('IcInfo:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="卡号 ">
                <a-input v-model="queryParam.icNo" allow-clear placeholder="请输入卡号 "/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="姓名 ">
                <a-input v-model="queryParam.patientName" allow-clear placeholder="请输入姓名 "/>
              </a-form-item>
            </a-col><template v-if="advanced">
              <a-col :md="8" :sm="24">
                <a-form-item label="性别 ">
                  <a-input v-model="queryParam.patientSex" allow-clear placeholder="请输入性别 "/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="生日 ">
                  <a-date-picker style="width: 100%" placeholder="请选择生日 " v-model="queryParam.birthdayDate" @change="onChangebirthday"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="建卡日期 ">
                  <a-date-picker style="width: 100%" placeholder="请选择建卡日期 " v-model="queryParam.foundDateDate" @change="onChangefoundDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="建卡人 ">
                  <a-input v-model="queryParam.foundName" allow-clear placeholder="请输入建卡人 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="操作员 ">
                  <a-input v-model="queryParam.operName" allow-clear placeholder="请输入操作员 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="身份证号 ">
                  <a-input v-model="queryParam.patientId" allow-clear placeholder="请输入身份证号 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="地址 ">
                  <a-input v-model="queryParam.address" allow-clear placeholder="请输入地址 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="电话 ">
                  <a-input v-model="queryParam.phone" allow-clear placeholder="请输入电话 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="邮箱 ">
                  <a-input v-model="queryParam.email" allow-clear placeholder="请输入邮箱 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="卡状态 0 注销 1正常 2停用 ">
                  <a-input v-model="queryParam.icStatus" allow-clear placeholder="请输入卡状态 0 注销 1正常 2停用 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="CRMID ">
                  <a-input v-model="queryParam.siCode" allow-clear placeholder="请输入CRMID "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="住院号 ">
                  <a-input v-model="queryParam.admNo" allow-clear placeholder="请输入住院号 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="卡类别 ">
                  <a-input v-model="queryParam.icType" allow-clear placeholder="请输入卡类别 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="工作地址 ">
                  <a-input v-model="queryParam.workAddr" allow-clear placeholder="请输入工作地址 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="备注 ">
                  <a-input v-model="queryParam.remark" allow-clear placeholder="请输入备注 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="咨询顾问 ">
                  <a-input v-model="queryParam.consultant" allow-clear placeholder="请输入咨询顾问 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="客户专员 ">
                  <a-input v-model="queryParam.consultanter" allow-clear placeholder="请输入客户专员 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="末次月经 ">
                  <a-input v-model="queryParam.menses" allow-clear placeholder="请输入末次月经 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="备注 ">
                  <a-input v-model="queryParam.back1" allow-clear placeholder="请输入备注 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="医院编码 ">
                  <a-input v-model="queryParam.hosptailCode" allow-clear placeholder="请输入医院编码 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="医院名称 ">
                  <a-input v-model="queryParam.hosptailName" allow-clear placeholder="请输入医院名称 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="档案号 ">
                  <a-input v-model="queryParam.danganNo" allow-clear placeholder="请输入档案号 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="医保备注">
                  <a-input v-model="queryParam.siRemark" allow-clear placeholder="请输入医保备注"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="APPID ">
                  <a-input v-model="queryParam.appid" allow-clear placeholder="请输入APPID "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="CRM备注 ">
                  <a-input v-model="queryParam.crmRemarks" allow-clear placeholder="请输入CRM备注 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="账户余额 ">
                  <a-input v-model="queryParam.accountfee" allow-clear placeholder="请输入账户余额 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="产检标志 ">
                  <a-input v-model="queryParam.cjbz" allow-clear placeholder="请输入产检标志 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="备注">
                  <a-input v-model="queryParam.remark1" allow-clear placeholder="请输入备注"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="1.不能退费、退卡；不开发票 2.不能退费、退卡、换卡 3.不能退费 4.不能退卡、换卡 5.不能开发票 ">
                  <a-input v-model="queryParam.icLevel" allow-clear placeholder="请输入1.不能退费、退卡；不开发票 2.不能退费、退卡、换卡 3.不能退费 4.不能退卡、换卡 5.不能开发票 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="会员卡类别 ">
                  <a-input v-model="queryParam.icStyle" allow-clear placeholder="请输入会员卡类别 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="建卡目的 ">
                  <a-input v-model="queryParam.createPurpose" allow-clear placeholder="请输入建卡目的 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="建卡科室 ">
                  <a-input v-model="queryParam.createDeptname" allow-clear placeholder="请输入建卡科室 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.fallassessment" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="退费原因 ">
                  <a-input v-model="queryParam.cancleReason" allow-clear placeholder="请输入退费原因 "/>
                </a-form-item>
              </a-col>            </template>

            <a-col :md="8" :sm="24" >
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)" >查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px"> {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>

          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false">
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :alert="true"
        :rowKey="(record) => record.iD"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }">
        <template class="table-operator" slot="operator" v-if="hasPerm('IcInfo:add')" >
          <a-button type="primary" v-if="hasPerm('IcInfo:add')" icon="plus" @click="$refs.addForm.add()">新增客户管理</a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a v-if="hasPerm('IcInfo:edit')" @click="$refs.editForm.edit(record)">编辑</a>
          <a-divider type="vertical" v-if="hasPerm('IcInfo:edit') & hasPerm('IcInfo:delete')"/>
          <a-popconfirm v-if="hasPerm('IcInfo:delete')" placement="topRight" title="确认删除？" @confirm="() => IcInfoDelete(record)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </s-table>
      <add-form ref="addForm" @ok="handleOk" />
      <edit-form ref="editForm" @ok="handleOk" />
    </a-card>
  </div>
</template>
<script>
  import { STable } from '@/components'
  import moment from 'moment'
  import { IcInfoPage, IcInfoDelete } from '@/api/modular/main/IcInfoManage'
  import addForm from './addForm.vue'
  import editForm from './editForm.vue'
  export default {
    components: {
      STable,
      addForm,
      editForm
    },
    data () {
      return {
        advanced: false, // 高级搜索 展开/关闭
        queryParam: {},
        columns: [
          {
            title: '卡号 ',
            align: 'center',
            dataIndex: 'icNo'
          },
          {
            title: '姓名 ',
            align: 'center',
            dataIndex: 'patientName'
          },
          {
            title: '性别 ',
            align: 'center',
            dataIndex: 'patientSex'
          },
          {
            title: '生日 ',
            align: 'center',
            dataIndex: 'birthday'
          },
          {
            title: '操作日期 ',
            align: 'center',
            dataIndex: 'operDate'
          },
          {
            title: '建卡日期 ',
            align: 'center',
            dataIndex: 'foundDate'
          },
          {
            title: '建卡人 ',
            align: 'center',
            dataIndex: 'foundName'
          },
          {
            title: '操作员编码 ',
            align: 'center',
            dataIndex: 'operCode'
          },
          {
            title: '操作员 ',
            align: 'center',
            dataIndex: 'operName'
          },
          {
            title: '拼音码 ',
            align: 'center',
            dataIndex: 'inputCode'
          },
          {
            title: '五笔码 ',
            align: 'center',
            dataIndex: 'inputCodeWb'
          },
          {
            title: 'VIP标志，没什么用 ',
            align: 'center',
            dataIndex: 'vipFlag'
          },
          {
            title: '身份证号 ',
            align: 'center',
            dataIndex: 'patientId'
          },
          {
            title: '地址 ',
            align: 'center',
            dataIndex: 'address'
          },
          {
            title: '电话 ',
            align: 'center',
            dataIndex: 'phone'
          },
          {
            title: '邮箱 ',
            align: 'center',
            dataIndex: 'email'
          },
          {
            title: '邮编 ',
            align: 'center',
            dataIndex: 'zip'
          },
          {
            title: '有效期 ',
            align: 'center',
            dataIndex: 'validDate'
          },
          {
            title: '卡状态 0 注销 1正常 2停用 ',
            align: 'center',
            dataIndex: 'icStatus'
          },
          {
            title: 'CRMID ',
            align: 'center',
            dataIndex: 'siCode'
          },
          {
            title: '住院号 ',
            align: 'center',
            dataIndex: 'admNo'
          },
          {
            title: '门诊号 ',
            align: 'center',
            dataIndex: 'outpNo'
          },
          {
            title: '是否打折 ',
            align: 'center',
            dataIndex: 'rebateType'
          },
          {
            title: '折扣 ',
            align: 'center',
            dataIndex: 'rebate'
          },
          {
            title: '余额 ',
            align: 'center',
            dataIndex: 'icFee'
          },
          {
            title: '累计消费 ',
            align: 'center',
            dataIndex: 'consumeFee'
          },
          {
            title: '卡类别 ',
            align: 'center',
            dataIndex: 'icType'
          },
          {
            title: '就诊号 ',
            align: 'center',
            dataIndex: 'icVisitNo'
          },
          {
            title: '联系人地址 ',
            align: 'center',
            dataIndex: 'linkmanAddr'
          },
          {
            title: '关联卡卡号 ',
            align: 'center',
            dataIndex: 'linkmanPhone'
          },
          {
            title: '关系 ',
            align: 'center',
            dataIndex: 'relationship'
          },
          {
            title: '工作地址 ',
            align: 'center',
            dataIndex: 'workAddr'
          },
          {
            title: '联系人 ',
            align: 'center',
            dataIndex: 'linkman'
          },
          {
            title: '套内折扣 ',
            align: 'center',
            dataIndex: 'rebate1'
          },
          {
            title: '备注 ',
            align: 'center',
            dataIndex: 'remark'
          },
          {
            title: '咨询顾问 ',
            align: 'center',
            dataIndex: 'consultant'
          },
          {
            title: '客户专员 ',
            align: 'center',
            dataIndex: 'consultanter'
          },
          {
            title: '末次月经 ',
            align: 'center',
            dataIndex: 'menses'
          },
          {
            title: '备注 ',
            align: 'center',
            dataIndex: 'back1'
          },
          {
            title: '医院编码 ',
            align: 'center',
            dataIndex: 'hosptailCode'
          },
          {
            title: '医院名称 ',
            align: 'center',
            dataIndex: 'hosptailName'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'theCallFlag'
          },
          {
            title: '导入备注 ',
            align: 'center',
            dataIndex: 'importantNote'
          },
          {
            title: '档案号 ',
            align: 'center',
            dataIndex: 'danganNo'
          },
          {
            title: 'APP卡号 ',
            align: 'center',
            dataIndex: 'appIcCode'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'bzj'
          },
          {
            title: '医保备注',
            align: 'center',
            dataIndex: 'siRemark'
          },
          {
            title: 'APPID ',
            align: 'center',
            dataIndex: 'appid'
          },
          {
            title: 'CRM备注 ',
            align: 'center',
            dataIndex: 'crmRemarks'
          },
          {
            title: '账户余额 ',
            align: 'center',
            dataIndex: 'accountfee'
          },
          {
            title: '产检标志 ',
            align: 'center',
            dataIndex: 'cjbz'
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark1'
          },
          {
            title: '1.不能退费、退卡；不开发票 2.不能退费、退卡、换卡 3.不能退费 4.不能退卡、换卡 5.不能开发票 ',
            align: 'center',
            dataIndex: 'icLevel'
          },
          {
            title: '会员卡类别 ',
            align: 'center',
            dataIndex: 'icStyle'
          },
          {
            title: '建卡目的 ',
            align: 'center',
            dataIndex: 'createPurpose'
          },
          {
            title: '建卡科室 ',
            align: 'center',
            dataIndex: 'createDeptname'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'fallassessment'
          },
          {
            title: '退费原因 ',
            align: 'center',
            dataIndex: 'cancleReason'
          }
        ],
        tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return IcInfoPage(Object.assign(parameter, this.switchingDate())).then((res) => {
            return res.data
          })
        },
        selectedRowKeys: [],
        selectedRows: []
      }
    },
    created () {
      if (this.hasPerm('IcInfo:edit') || this.hasPerm('IcInfo:delete')) {
        this.columns.push({
          title: '操作',
          width: '150px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        })
      }
    },
    methods: {
      moment,
      /**
       * 查询参数组装
       */
      switchingDate () {
        const queryParambirthday = this.queryParam.birthdayDate
        if (queryParambirthday != null) {
            this.queryParam.birthday = moment(queryParambirthday).format('YYYY-MM-DD')
            if (queryParambirthday.length < 1) {
                delete this.queryParam.birthday
            }
        }
        const queryParamfoundDate = this.queryParam.foundDateDate
        if (queryParamfoundDate != null) {
            this.queryParam.foundDate = moment(queryParamfoundDate).format('YYYY-MM-DD')
            if (queryParamfoundDate.length < 1) {
                delete this.queryParam.foundDate
            }
        }
        const obj = JSON.parse(JSON.stringify(this.queryParam))
        return obj
      },
      IcInfoDelete (record) {
        IcInfoDelete(record).then((res) => {
          if (res.success) {
            this.$message.success('删除成功')
            this.$refs.table.refresh()
          } else {
            this.$message.error('删除失败') // + res.message
          }
        })
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      onChangebirthday(date, dateString) {
        this.birthdayDateString = dateString
      },
      onChangefoundDate(date, dateString) {
        this.foundDateDateString = dateString
      },
      handleOk () {
        this.$refs.table.refresh()
      },
      onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      }
    }
  }
</script>
<style lang="less">
  .table-operator {
    margin-bottom: 18px;
  }
  button {
    margin-right: 8px;
  }
</style>
